package com.hunan.yllxy.repostitory.entity;

import cn.afterturn.easypoi.excel.annotation.Excel;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.hunan.yllxy.util.Preconditions;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

/**
 * <p>
 * 
 * </p>
 *
 * @author 刘华
 * @since 2025-06-16
 */
@Getter
@Setter
@TableName("user_info")
@ApiModel(value = "UserInfo对象", description = "")
public class UserInfo extends Model<UserInfo> implements UserDetails {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.ASSIGN_UUID)
    private String id;

    @Excel(name = "用户名", height = 20, width = 30, isImportField = "true_st")
    @TableField("user_name")
    private String userName;

    @Excel(name = "账户", height = 20, width = 30, isImportField = "true_st")
    @TableField("account")
    private String account;

    @TableField("password")
    private String password;

    @Excel(name = "性别", height = 20, width = 30, isImportField = "true_st")
    @TableField("gender")
    private String gender;

    @Excel(name = "手机号", height = 20, width = 30, isImportField = "true_st")
    @TableField("phone")
    private String phone;

    @TableField(exist = false)
    private List<DakaContentInfo> dakaContentInfos;

    @TableField(exist = false)
    private List<SimpleGrantedAuthority> authorityList = new ArrayList<>();

    @TableField(exist = false)
    private List<String> showRoleNames = new ArrayList<>();


    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorityList;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    @Override
    public String getUsername() {
        return account;
    }

    @Override
    @JsonIgnore
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    @JsonIgnore
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    @JsonIgnore
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    @JsonIgnore
    public boolean isEnabled() {
        return true;
    }

    public void check() {
        Preconditions.checkNullArgument(userName,"姓名");
        Preconditions.checkNullArgument(phone,"手机号");
        Preconditions.checkNullArgument(account,"账号");
//        Preconditions.checkNullArgument(gender,"性别");
    }
}
